package homework.mid_autumn_festival.string_exercise;

public class StringBuilderDemo {
    public static void main(String[] args) {

        String str = "好好学习Java";
        StringBuilder builder = new StringBuilder(str);

        //append
        builder.append(",为了找到赚钱多一些的工作");
        System.out.println(builder);
        System.out.println(builder.length());

        //replace
        builder.replace(9,builder.length(),"为了拯救世界");//含头不含尾
        System.out.println(builder);

        //delete
        builder.delete(0,8);//含头不含尾
        System.out.println(builder);

        //insert
        builder.insert(0,"活着");
        System.out.println(builder);

        //reverse
        builder.reverse();
        System.out.println(builder);//界世救拯了为,着活

        //String和StringBuilder互转
        String s1 = "abc";
        StringBuilder builder1 = new StringBuilder(s1);//String转Builder
        String s3 = builder1.toString();//Builder转String

    }
}
